// 事件分发管理

const EventListener = function(obj) {
    let Register = {};

    obj.on = function(type, method) {
        if (Register.hasOwnProperty(type)) {
            Register[type].push(method);
        } else {
            Register[type] = [method];
        }
    };

    obj.fire = function(type) {
        if (Register.hasOwnProperty(type)) {
            let handLerList = Register[type];
            for (let i = 0; i < handLerList.length; i++) {
                const handLer = handLerList[i];
                let args = [];
                // arguments默认的参数列表
                for (let j = 0; j < arguments.length; j++) {
                    args.push(arguments[j]);
                }
                handLer.apply(this, args);
            }
        }
    };

    obj.removeListener = function(type, method) {
        
    };

    obj.removeAllListeners = function() {

    };

    return obj;
};

export default EventListener;